package com.bea.ftd.dashboard.validator;

import java.util.stream.Stream;

import org.springframework.stereotype.Component;

import com.bea.ftd.common.enums.EncryptEnum;
import com.bea.ftd.common.enums.EncryptStrategy;
import com.bea.ftd.common.enums.MsgType;
import com.bea.ftd.common.enums.ParamType;
import com.bea.ftd.common.enums.RateLimiteTypeEnum;

@Component
public class CustomTypeValidator {


	/**
	 * 验证是否是有效的的EncryptStrategy枚举
	 * 
	 * @param id
	 * @return
	 */
	public boolean isValidEncryptStrategy(Long id) {
		if (null == id) {
			return false;
		}
		return id >= 0 && id < EncryptStrategy.values().length;
	}

	/**
	 * 验证是否是有效的的MsgType枚举类型
	 * 
	 * @param id
	 * @return
	 */
	public boolean isValidMessageType(String type) {
		return Stream.of(MsgType.values()).map(MsgType::name).anyMatch(name -> name.equalsIgnoreCase(type));
	}
	
	public boolean isValidParamType(String type) {
		return Stream.of(ParamType.values()).map(ParamType::name).anyMatch(name -> name.equalsIgnoreCase(type));
	}

	/**
	 * 验证是否是有效的RateLimiteTypeEnum枚举类型
	 * 
	 * @param type
	 * @return
	 */
	public boolean isValidRateLimiteInfoType(String type) {
		return Stream.of(RateLimiteTypeEnum.values()).map(RateLimiteTypeEnum::name)
				.anyMatch(name -> name.equalsIgnoreCase(type));
	}

	/**
	 * 验证是否是有效的EncryptEnum枚举(加密或验签)类型
	 * 
	 * @param type
	 * @return
	 */
	public boolean isValidEncrytType(String type) {
		return Stream.of(EncryptEnum.values()).map(EncryptEnum::name).anyMatch(name -> name.equalsIgnoreCase(type));
	}

}
